package com.example.userprofile

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object WebServiceFactory {

    @Provides
    @Singleton
    fun httpClient(): OkHttpClient = OkHttpClient.Builder().build()

    @Provides
    @Singleton
    fun retrofit(okHttpClient : OkHttpClient): Retrofit = Retrofit.Builder()
            .client(okHttpClient)
            .baseUrl("http://localhost:8080/api")
            .build()

    @Provides
    @Singleton
    fun userWebservice(retrofit: Retrofit): UserWebservice =  retrofit.create(UserWebservice::class.java)
}